package com.ming.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ming.yygh.common.result.Result;
import com.ming.yygh.model.user.UserInfo;
import com.ming.yygh.user.service.UserInfoService;
import com.ming.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Light
 * @date 2021/12/21 17:29
 */
@Api(tags = "用户管理接口")
@RestController
@RequestMapping("admin/user")
public class UserController {

    @Resource
    private UserInfoService userInfoService;

    // 用户列表接口(条件查询带分页)
    @ApiOperation(value = "用户列表接口(条件查询带分页)")
    @GetMapping("{page}/{limit}")
    public Result<IPage<UserInfo>> list(@PathVariable(value = "page") Long page,
                                        @PathVariable(value = "limit") Long limit,
                                        UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> pageParam = new Page<>(page, limit);
        IPage<UserInfo> pageModel = userInfoService.selectPage(pageParam, userInfoQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "用户锁定")
    @GetMapping("/lock/{userId}/{status}")
    public Result<Boolean> lock(@PathVariable(value = "userId") String userId,
                                @PathVariable(value = "status") Integer status) {
        userInfoService.lock(userId, status);
        return Result.ok();
    }

    @ApiOperation(value = "用户详情")
    @GetMapping("/show/{userId}")
    public Result show(@PathVariable(value = "userId") String userId) {
        Map<String, Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    @ApiOperation(value = "认证审批接口")
    @GetMapping("/approval/{userId}/{authStatus}")
    public Result<Boolean> approval(@PathVariable(value = "userId") String userId,
                           @PathVariable(value = "authStatus") Integer authStatus) {
        userInfoService.approval(userId, authStatus);
        return Result.ok();
    }


}
